<!DOCTYPE html>
<html>
<head>
	<title>修改密码</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<style type="text/css">
		body{
			width:1366px;
			height:768px;
			background:url(images/1.jpg);
			background-size:100% 100%;
			margin:0 auto;
		}	
		center{
			padding-top:60px;
		}	   
		input{
			width:200px;
			height:40px;
			font-size:20px;
			padding-left:10px;
			margin-top:20px;
		}
		#sub{
			width:120px;
			height:40px;
			text-align:center;
			font-size: 14px;


			line-height: 40px;

			color: black;
			background-color: #eaeaea;
			border-radius: 6px;
			border: 0;
		}
		#login_frame {
			width: 440px;
			height: 360px;
			padding: 13px;

			position: absolute;
			left: 50%;
			top: 40%;
			margin-left: -200px;
			margin-top: -200px;

			background-color: rgba(240, 255, 255, 0.5);

			border-radius: 10px;
			text-align: center;
			
		}
		.text_field {
			width: 278px;
			height: 28px;
			margin: 5px;
			border-radius: 5px;
			border: 0;
			background-color: white: 
		}
	</style>
</head>
<body>
<div id="login_frame">
	<?php
	echo  "<center>";
	echo "<h1>欢迎使用智能考试系统！</h1><p>";
	if (null==($_COOKIE["user"] OR $_COOKIE["user"]==" "))
	{
		echo "你还没有登录!<p>";
		echo "<a href='login_l.php'>登录</a> &nbsp;&nbsp;&nbsp;<a href='reg_l.php'>注册</a>";
	}
	else
	{
		if(null==$_POST["pass"])
		{
			?>
			<table>
				<form action ="edit_pass.php" method="post">
					<h2 align="center">修改密码</h2>
					<tr>
						<td>用户名：</td>
						<td><?php echo $_COOKIE["user"]?></td>
					</tr>
					<tr>
						<td>输入旧密码：</td>
						<td><input class="text_field" type="password" name="pass"></td>
					</tr>
					<tr>
						<td>输入新密码：</td>
						<td><input class="text_field" type="password" name="new_pass"></td>
					</tr>
					<tr>
						<td colspan="2" align="center"><input id="sub" type="submit" value="确认修改"></td>
					</tr>
				</form>
			</table>
			<a href="index.php"><big><b>返回</b></big></a>
			<?php
		}
		else
		{
			$user=$_COOKIE["user"];
			$pass=$_POST["pass"];
			$new_pass=$_POST["new_pass"];
			include "config.php";
			$sql="select count(id) from db_user where name='$user' and pass='$pass'";
			$result=$mysqli->query($sql) or die($mysqli->error);
			$num=$result->num_rows;
			if($num==0)
			{
				echo "用户名或密码错误!";
				echo "单击<a href='edit_pass.php'>这里</a>重新输入";
			}
			else
			{
				$sql="update db_user set pass='$new_pass' where name='$user' and pass='$pass'";
				$result=$mysqli->query($sql) or die($mysqli->error);
				if($result)
				{
					echo "<big><b>密码修改成功！</b></big>";
					echo "<p><a href='index.php'><b><big>返回</big></b></a>";
				}
				else
				{
					echo "密码修改出错";
					echo "<p>单击<a href='edit_pass.php'>这里</a>重新修改密码";
				}
			}
		}
	}
	?>
</div>
</body>
</html>